<template>
  <pro-layout
    :menus="menus"
    :collapsed="collapsed"
    :mediaQuery="query"
    :isMobile="isMobile"
    :handleMediaQuery="handleMediaQuery"
    :handleCollapse="handleCollapse"
    :footer-render="false"
    v-bind="settings"
	
  >
    <template #menuHeaderRender>
			<div @click="menuHeaderClick" style="position: absolute;left: 0;top: 0;" class="w100  flex flex-col items-center">
			  <img src="../assets/logo.png" class="ss-logo wh" />
<!--			  <h1 class="m-0" style="margin: 0;">宠主管</h1>-->
			</div>
    </template>
    <template #rightContentRender>
      <right-content :top-menu="settings.layout === 'topmenu'" :is-mobile="isMobile" :theme="settings.theme" />
    </template>
    <router-view />
  </pro-layout>
</template>

<script>
import { SettingDrawer } from '@ant-design-vue/pro-layout'
import { mapState } from 'vuex'
import { CONTENT_WIDTH_TYPE, SIDEBAR_TYPE, TOGGLE_MOBILE_TYPE } from '@/store/mutation-types'
import { get } from 'lodash'
import defaultSettings from '@/config/defaultSettings'
import RightContent from '@/components/GlobalHeader/RightContent'
import GlobalFooter from '@/components/GlobalFooter'
import Ads from '@/components/Other/CarbonAds'
import LogoSvg from '../assets/logo.svg?inline'

export default {
  name: 'BasicLayout',
  components: {
    SettingDrawer,
    RightContent,
    GlobalFooter,
    LogoSvg,
    Ads,
  },
  data() {
    return {
      // preview.pro.antdv.com only use.
      isProPreviewSite: process.env.VUE_APP_PREVIEW === 'true' && process.env.NODE_ENV !== 'development',
      // end
      isDev: process.env.NODE_ENV === 'development' || process.env.VUE_APP_PREVIEW === 'true',

      // 侧栏收起状态
      collapsed: false,
      title: defaultSettings.title,
      topRouteKeys: ['home'],
      settings: {
        // 布局类型
        layout: defaultSettings.layout, // 'sidemenu', 'topmenu'
        // CONTENT_WIDTH_TYPE
        contentWidth: defaultSettings.layout === 'sidemenu' ? CONTENT_WIDTH_TYPE.Fluid : defaultSettings.contentWidth,
        // 主题 'dark' | 'light'
        theme: defaultSettings.navTheme,
        // 主色调
        primaryColor: defaultSettings.primaryColor,
        fixedHeader: defaultSettings.fixedHeader,
        fixSiderbar: defaultSettings.fixSiderbar,
        colorWeak: defaultSettings.colorWeak,

        hideHintAlert: false,
        hideCopyButton: false,
      },
      // 媒体查询
      query: {},

      // 是否手机模式
      isMobile: false,
    }
  },
  computed: {
    ...mapState({
      // 动态主路由
      mainMenu: (state) => state.permission.addRouters,
    }),
    // topMenus() {
    //   return this.mainMenu.filter((e) => e.meta && e.meta.isTopMenu)
    // },
    // menus() {
    //   const routes = this.mainMenu.find((item) => item.meta && item.meta.menu === this.topRouteKeys[0])
    //   return (routes && routes.children) || []
    // },
  },
  created() {
    // this.menus = this.mainMenu
    // 处理侧栏收起状态
    const routes = this.mainMenu.find(item => item.path === '/')
    this.menus = (routes && routes.children) || []
    console.log( this.menus)
    this.$watch('collapsed', () => {
      this.$store.commit(SIDEBAR_TYPE, this.collapsed)
    })
    this.$watch('isMobile', () => {
      this.$store.commit(TOGGLE_MOBILE_TYPE, this.isMobile)
    })
  },
  mounted() {
    const userAgent = navigator.userAgent
    if (userAgent.indexOf('Edge') > -1) {
      this.$nextTick(() => {
        this.collapsed = !this.collapsed
        setTimeout(() => {
          this.collapsed = !this.collapsed
        }, 16)
      })
    }
    // if (process.env.NODE_ENV !== 'production' || process.env.VUE_APP_PREVIEW === 'true') {
    //   updateTheme(this.settings.primaryColor)
    // }
    // first update color
    // TIPS: THEME COLOR HANDLER!! PLEASE CHECK THAT!!
    // if (process.env.NODE_ENV !== 'production' || process.env.VUE_APP_PREVIEW === 'true') {
    // 	updateTheme(this.settings.primaryColor)
    // }
  },
  methods: {
    menuHeaderClick() {
      this.topRouteKeys = ['home']
    },
    handleMediaQuery(val) {
      this.query = val
      if (this.isMobile && !val['screen-xs']) {
        this.isMobile = false
        return
      }
      if (!this.isMobile && val['screen-xs']) {
        this.isMobile = true
        this.collapsed = false
        this.settings.contentWidth = CONTENT_WIDTH_TYPE.Fluid
        // this.settings.fixSiderbar = false
      }
    },
    handleCollapse(val) {
      this.collapsed = val
    },
  },
}
</script>

<style lang="less" scoped>
@import './BasicLayout.less';
.ss-logo {
  // border: 2px solid rgba(255, 255, 255, 0.5);
}
.flex {
  display: flex;
  align-items: center;
  justify-content: center
}

.top-nav {
  .flex;
  height: 100%;

  .ant-menu-horizontal {
    line-height: 64px;
    font-size: 16px;
    font-weight: bolder;

    .ant-menu-item {
      text-align: center;
      min-width: 120px;

      &-selected {
        color: #1890ff;
        border-bottom: 2px solid #1890ff;
        background: #1890ff10;
      }
    }
  }
}
.bkEF {
  background: #efbc3b;
}
/deep/.ant-pro-sider-menu-logo {
  //height: 120px;
}
.w100{
  width: 100%;
}
.wh{
  width: 62px;
  height: 62px;
}
</style>
